package org.dant.ant.extension.tasks;

import java.io.*;
import java.util.*;
import org.dant.ant.extension.tasks.internal.Endpoint;
import org.dant.ant.extension.tasks.internal.RemoteResponse;
import org.dant.ant.extension.tasks.commands.CopyCommand;
import org.dant.ant.extension.tasks.internal.RemoteCommand;

public class RemoteCopy extends RemoteTask {

  protected String srcdir = null;
  protected String destdir = null;
  protected String filename = null;
  protected String filetype = null;
  protected String rename = null;
  
  public RemoteCopy() {
    rcmd = new CopyCommand();
  }

  public void setCopyCommand(CopyCommand cmd) {
    this.rcmd = cmd;
  }

  public void setRename(String rename) {
    this.rename = rename;
  }
  public String getRename() {
    return this.rename;
  }
  
  public void setSrcdir(String dir) {
    this.srcdir = dir;
  }
  
  public void setDestdir(String dir) {
    this.destdir = dir;
  }
  
  public void setFilename(String filename) {
    this.filename = filename;
  }
  
  public void setFiletype(String filetype) {
    this.filetype = filetype;
  }

  public String getSrcdir() {
    return this.srcdir;
  }

  public String getDestdir() {
    return this.destdir;
  }

  public String getFilename() {
    return this.filename;
  }

  public String getFiletype() {
    return this.filetype;
  }
  
  public void resolveDir() throws IOException {
    for (Iterator iter=destHosts.keySet().iterator(); iter.hasNext();) {
      Endpoint ep = (Endpoint) iter.next();
      CopyCommand request = (CopyCommand)destHosts.get(ep);
      File basedir = ep.getBaseDir();
      File destDir = new File(request.getFullDestPath());
      if (basedir == null || destDir.isAbsolute()) continue;
      File absolutePath = fu.resolveFile(basedir, request.getFullDestPath());
      request.appendParameters("fulldestpath", absolutePath.getCanonicalPath());
    }
  }
}
